using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Musicman.Entities;
using Musicman.Business;

namespace MusicmanWeb.Custom
{
    public partial class MyRegisterControl : System.Web.UI.UserControl
    {
        private string appServer;

        public string AppServer
        {
            get { return appServer; }
            set { appServer = value; }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            if (Page.IsValid)
            {
                User user = new User();
                user.Firstname = this.FirstNameTxt.Text;
                user.Lastname = this.LastNameTxt.Text;
                user.Emailaddress = this.EmailTxt.Text;
                user.Password = DataManager.Instance.PassEncrypting(this.PasswordTxt.Text);
                user.MailRequest = this.RQEmalCb.Checked;
                user.ActivationCode = Guid.NewGuid();

                DataManager.Instance.CreateNewUser(user);
                MailManager.Instance.SendActivationMail(user, this.appServer);


                this.Panel1.Visible = false;
                this.Panel2.Visible = true;
            }
            
        }

        protected void Check_Email(object source, ServerValidateEventArgs args)
        {
            if (DataManager.Instance.CheckUserExist(args.Value))
            {
                args.IsValid = false;
            }
        }
    }
}